import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

  {
    path: '/dashboardPage',
    name: 'dashboardPage',
    component: () => import('@/views/dashboard/welcome/index'),
    meta: { title: 'dashboardPage', icon: 'dashboardPage' }

  },
  {
    path: '/SysPassworMan',
    name: 'SysPassworMan',
    component: () => import('@/views/permission/views/system-password/index'),
    meta: { title: 'SysPassworMan', icon: 'SysPassworMan' }
  },
  // 用户管理
  {
    path: '/userManagemenet',
    name: 'UserManagemenet',
    component: () => import('@/views/permission/views/user-management/index'),
    meta: { title: 'UserManagemenet', icon: 'UserManagemenet' }
  },
  // 资源管理
  {
    path: '/moulds-mangement/sys-resu-d',
    name: 'ResourceManagement',
    component: () => import('@/views/permission/views/resource-management/index'),
    meta: { title: 'ResourceManagement', icon: 'el-icon-document' }
  },
  // 子系统管理
  {
    path: '/subsys/sys-subsys-d',
    name: 'SubsysManagement',
    component: () => import('@/views/permission/views/subsystem-management/index'),
    meta: { title: 'SubsysManagement', icon: 'el-icon-document' }
  },
  // 安全角色管理
  {
    path: '/security-role-management',
    name: 'SecurityRoleManagement',
    component: () => import('@/views/permission/views/security-role-management/index'),
    meta: { title: 'SecurityRoleManagement', icon: 'el-icon-document' }
  },
  // 业务角色管理
  {
    path: '/busirole-management',
    name: 'BusiroleManagement',
    component: () => import('@/views/permission/views/busirole-management/index'),
    meta: { title: 'BusiroleManagement', icon: 'el-icon-document' }
  }, {
    path: '/password-reset',
    name: 'PasswordReset',
    component: () => import('@/views/permission/views/password-reset/index'),
    meta: { title: 'PasswordReset', icon: 'el-icon-document' }
  }, {
    path: '/role-perm-chg-evt',
    name: 'RolePermChgEvt',
    component: () => import('@/views/permission/views/role-perm-chg-evt/index'),
    meta: { title: 'RolePermChgEvt', icon: 'el-icon-document' }
  }, {
    path: '/securityLog-mngr',
    name: 'SecurityLogMngr',
    component: () => import('@/views/permission/views/securityLog-mngr/index'),
    meta: { title: 'SecurityLogMngr', icon: 'el-icon-document' }
  }, {
    path: '/user-lock-mngr',
    name: 'userLockMngr',
    component: () => import('@/views/permission/views/user-lock-mngr/index'),
    meta: { title: 'userLockMngr', icon: 'el-icon-document' }
  }, {
    path: '/organiz/sys-orgunt-d',
    name: 'sysOrguntD',
    component: () => import('@/views/permission/views/sys-orgunt-d/index'),
    meta: { title: 'sysOrguntD', icon: 'el-icon-document' }
  },
  {
    path: '/sys-menu-fav-d',
    name: 'sysMenuFavD',
    component: () => import('@/views/permission/views/sys-menu-fav-d/index'),
    meta: { title: 'sysMenuFavD', icon: 'el-icon-document' }
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
